import django_filters
from django.contrib.auth import get_user_model
from apps.work.models import All_Kq_Infos, All_Kq_Orders, Kq_Extend_infos, Kq_Maintain_infos, Kq_Price_infos, \
    Kq_All_Pumps,Kq_All_Projects,Comp_Dept,Comp_Role,Comp_User
from apps.vadmin.utils.model_util import get_dept
UserProfile = get_user_model()

class UserProfileFilter(django_filters.rest_framework.FilterSet):
    """
    用户管理 简单序过滤器
    """
    name = django_filters.CharFilter(lookup_expr='icontains')
    mobile = django_filters.CharFilter(lookup_expr='icontains')
    deptId = django_filters.CharFilter(method='filter_deptId')

    def filter_deptId(self, queryset, name, value):
        return queryset.filter(dept__id__in=get_dept(dept_id=value))

    class Meta:
        model = Comp_User
        exclude = ('secret', 'password',)



class RoleFilter(django_filters.rest_framework.FilterSet):
    """
    角色管理 简单序过滤器
    """
    roleName = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Comp_Role
        exclude = ('description', 'creator', 'modifier')

class DeptFilter(django_filters.rest_framework.FilterSet):
    """
    部门管理 简单序过滤器
    """
    deptName = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Comp_Dept
        exclude = ('description', 'creator', 'modifier')

class WorkFilter(django_filters.rest_framework.FilterSet):
    # 客户库 简单序过滤器
    # 通过 lookup_expr 可进行模糊查询，其他配置可自行百度

    compName = django_filters.CharFilter(lookup_expr='icontains')
    province = django_filters.CharFilter(lookup_expr='icontains')
    city = django_filters.CharFilter(lookup_expr='icontains')
    district = django_filters.CharFilter(lookup_expr='icontains')
    collaborator = django_filters.CharFilter(lookup_expr='icontains')
    # collDepartment = django_filters.CharFilter(lookup_expr='icontains')
    businessProgress = django_filters.CharFilter(lookup_expr='icontains')
    parCompName = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = All_Kq_Infos
        exclude = ('description', 'creator', 'modifier')


class OrderFilter(django_filters.rest_framework.FilterSet):
    """
    订单 简单序过滤器
    """
    # 通过 lookup_expr 可进行模糊查询，其他配置可自行百度

    compName = django_filters.CharFilter(lookup_expr='icontains')
    collaborator = django_filters.CharFilter(lookup_expr='icontains')
    position = django_filters.CharFilter(lookup_expr='icontains')
    maxDepartment = django_filters.CharFilter(lookup_expr='icontains')
    department = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = All_Kq_Orders
        exclude = ('description', 'creator', 'modifier')


class KqExtendInfoFilter(django_filters.rest_framework.FilterSet):
    """
    拓展信息 简单序过滤器
    """

    compName = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Kq_Extend_infos
        exclude = ('description', 'creator', 'modifier')


class KqMaintainInfoFilter(django_filters.rest_framework.FilterSet):
    """
    维护中心 简单序过滤器
    """

    compName = django_filters.CharFilter(lookup_expr='icontains')
    name = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Kq_Maintain_infos
        exclude = ('description', 'creator', 'modifier')


class KqPriceInfoFilter(django_filters.rest_framework.FilterSet):
    """
    报价中心 简单序过滤器
    """

    compName = django_filters.CharFilter(lookup_expr='icontains')
    projectName = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Kq_Price_infos
        exclude = ('description', 'creator', 'modifier')


class KqPumpsFilter(django_filters.rest_framework.FilterSet):
    """
    pump 简单序过滤器
    """

    type = django_filters.CharFilter(lookup_expr='icontains')
    kind = django_filters.CharFilter(lookup_expr='icontains')
    calibre = django_filters.CharFilter(lookup_expr='icontains')
    flow = django_filters.CharFilter(lookup_expr='icontains')
    height = django_filters.CharFilter(lookup_expr='icontains')
    power = django_filters.CharFilter(lookup_expr='icontains')
    compType = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Kq_All_Pumps
        exclude = ('creator', 'modifier')


class KqAllProjectsFilter(django_filters.rest_framework.FilterSet):
    """
    project 简单序过滤器
    """

    projectName = django_filters.CharFilter(lookup_expr='icontains')
    buyer = django_filters.CharFilter(lookup_expr='icontains')
    seller = django_filters.CharFilter(lookup_expr='icontains')

    class Meta:
        model = Kq_All_Projects
        exclude = ('description', 'creator', 'modifier')
